package createThread;

import java.util.concurrent.*;

/**
 * 第三种创建线程的方式
 * 继承Callable接口,
 * callable中可以在线程运行的时候定义返回值
 */
public class CreateThreadByCallable {
    public static void main(String[] args) {
        FutureTask futureTask = new FutureTask(new MyCall());
        Thread thread = new Thread(futureTask);
        thread.start();
        try {
            Object o = futureTask.get();
            System.out.println("执行的结果为"+o);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}

class MyCall implements Callable<Integer>{
    private Integer value = 100;

    public Integer call() throws Exception {
        System.out.println("thread is run ....");
        Thread.sleep(1000);
        if(value ==100){
            return 10;
        }
        if(value == 1000){
            return 100;
        }
        return 1;
    }
}
